package com.aimusic.service.impl;

import com.aimusic.domain.po.UserProfile;
import com.aimusic.mapper.UserProfileMapper;
import com.aimusic.service.IUserProfileService;
import com.aimusic.utils.CurrentHolder;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author
 * @since 2025-09-28
 */
@Service
@Slf4j
public class UserProfileServiceImpl extends ServiceImpl<UserProfileMapper, UserProfile> implements IUserProfileService {
    @Override
    public UserProfile getUserInfo() {
        //根据用户id查询用户信息
        Integer userId = CurrentHolder.getCurrentId();
        UserProfile userProfile = lambdaQuery().eq(UserProfile::getUserId, userId).one();
        return userProfile;
    }

    @Override
    public void updateProfile(UserProfile userProfile) {
        //根据用户id更新用户信息
        Integer userId = CurrentHolder.getCurrentId();
        userProfile.setUserId(userId.longValue());
        update(userProfile, new QueryWrapper<UserProfile>().eq("user_id", userId));
    }
}
